<div class = "main-view">
    <div class="left-margin top-margin"><strong class="am-text-primary am-text-lg">卡片管理</strong></div>
    <form class="am-form-inline left-margin top-margin" role="form">
        <div class="am-form-group">
            <label>卡片标题：</label> <input type="text" class="modal-input" style="height: 30px" ng-model="cardTitle" >
        </div>

        <button type="submit" class="am-btn am-btn-primary" ng-click="search($event)" data-target = "cascad-search">搜索</button>
    </form>
    <br>
    <div class="am-btn-group am-btn-group-xs left-margin top-margin">
        <button type="button" class="am-btn am-btn-default" data-am-modal="{target: '#doc-modal-add', width: 800, height: 600}"><span class="am-icon-plus"></span>添加卡片</button>
        <button type="button" class="am-btn am-btn-default" ng-click="delete()"><span class="am-icon-trash-o"></span> 删除</button>
    </div>
    <div id = "pagination" class = "pagination"></div>
    <div class="pagination-table left-margin" id="tab_menu" style = "margin-top: 0px;">
        <form class="am-form">
            <table class="am-table-striped am-table-hover table-main">
                <thead>
                <tr>
                    <th class="table-check"><input type="checkbox" ng-click="allSelected()"></th>
                    <!--<th>序号</th>-->
                    <th>卡片标题</th>
                    <th>排序</th>
                    <th>url</th>
                    <th>级别</th>
                    <th>区域</th>
                    <th>开始日期</th>
                    <th>结束日期</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr ng-repeat="result in resultList"  id = "{{result.objId}}">
                    <td class="table-check"><input type="checkbox" class = "item-check"></td>
                    <!--<td>{{result.id}}</td>-->
                    <td>{{result.title}}</td>
                    <td>{{result.cardOrder}}</td>
                    <td>{{result.url}}</td>
                    <td>{{result.level}}</td>
                    <td>{{result.province.name+' '+result.city.name +' '+result.county.name+' '}}</td>
                    <td>{{result.beginDate|date:"yyyy-MM-dd HH:mm:ss"}}</td>
                    <td>{{result.endDate|date:"yyyy-MM-dd HH:mm:ss"}}</td>
                    <!--<th><span ng-show="result.is_publish==0">否</span><span ng-show="result.is_publish==1">是</span></th>-->

                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">

                                <button type="button" class="am-btn am-btn-default am-btn-xs am-hide-sm-only" ng-click="cardEdit(result)" >编辑</button>
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-hide-sm-only" ng-click="cardPushShow(result)" >推送</button>
                            </div>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class = "left-margin">共<span id = 'page_number'>{{pageNumber}}</span>页 <span>{{count}}条数据</span></div>
    <!--新增框 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-add">
        <div class="am-modal-dialog">
            <div class="am-modal-hd border-bottom" style = "text-align: left;">新增卡片
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div style="position:absolute; left:10%; right:10%;">
                <div class="am-modal-bd body-area text-left">
                    <form>
                        <br>
                        <label style="width:auto">卡片标题:</label><input class="modal-input" ng-model="addData.cardTitle" >
                        <label style="width:auto">打开方式：</label>
                        <select data-am-selected="{btnSize: 'sm'}" ng-model="addData.openType" style="margin-left: 0px;">
                            <!--<option value=1>问答</option>-->
                            <option value=3>活动/H5</option>
                            <option value=4>专题</option>
                            <!--<option value=12>商品详情页</option>-->
                            <option value=14>积分商城</option>
                            <option value=16>邀请有礼</option>
                        </select>
                        <br>
                        <div>
                            <label style="width:auto">开始时间:</label><input type="text" class="modal-input" ng-model="addData.beginDate" id ="begin_add">
                            <label style="width:auto">结束时间:</label><input type="text" class="modal-input" ng-model="addData.endDate" id ="end_add">
                        </div>
                        <br>
                        <label class="control-label">卡片描述:</label><br />
                        <textarea style="width:600px;height:100px;" ng-model="addData.cardDesc" ></textarea>
                        <br>
                        <label>设置卡片的区域:</label><br>
                        <div class = "city-cascading" style = "display: inline-block;" id = "cascad-search-add"></div>
                        <br />
                        <!--<label class="control-label">摇奖次数(次/人)：</label>-->
                        <!--<input class="form-control" ng-model="addData.limitCount" >-->
                        <!--<br />-->
                        <!--<label class="control-label">活动描述：</label><br />-->
                        <!--<textarea style="width:600px;height:200px;" ng-model="addData.activityDesc" ></textarea>-->
                        <!--<br /><br />-->
                        <label> 卡片图片</label><br>
                        <div class="col-xs-5">
                            <input type="file" id="pict"
                                   onchange="angular.element(this).scope().selectFile(this.files)" accept="image/*"></div>
                        <br/>
                        <label class="control-label">URL：</label><br />
                        <input type="text" class = "modal-input" style = "width: 600px;display: inline-block;" ng-model="addData.url" required>
                        <br/>
                        <label class="control-label">卡片顺序：</label><br />
                        <input type="text" class = "modal-input" style = "width: 60px;display: inline-block;" ng-model="addData.cardOrder">
                    </form>
                </div>
                <div class = "button-area border-top">
                <button type="button" class="am-btn am-btn-success right-margin top-margin" ng-show="true" ng-click="add(addData,$event)" data-target = "cascad-search-add">保存</button>
            </div>
            </div>
        </div>
    </div>
    <!--编辑框 -->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-edit">
        <div class="am-modal-dialog">
            <div class="am-modal-hd border-bottom" style = "text-align: left;">编辑卡片
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <div style="position:absolute; left:10%; right:10%;">
                <div class="am-modal-bd body-area text-left">
                    <form>
                        <br>
                        <label style="width:auto">卡片标题:</label><input class="modal-input" ng-model="updateDate.title" >
                        <label style="width:auto">打开方式:</label>
                        <select data-am-selected="{btnSize: 'sm'}" ng-model="updateDate.openType" style="margin-left: 0px;">
                            <option value=1>问答</option>
                            <option value=3>活动/H5</option>
                            <option value=4>专题</option>
                            <!--<option value=12>商品详情页</option>-->
                            <option value=14>积分商城</option>
                            <option value=16>邀请有礼</option>
                        </select>
                        <br>
                        <div>
                            <label style="width:auto">开始时间:</label><input type="text" class="modal-input" ng-model="updateDate.beginDate" id ="begin_edit">
                            <label style="width:auto">结束时间:</label><input type="text" class="modal-input" ng-model="updateDate.endDate" id ="end_edit">
                        </div>
                        <br>
                        <label class="control-label">卡片描述:</label><br />
                        <textarea style="width:600px;height:100px;" ng-model="updateDate.desc" ></textarea>
                        <br>
                        <label>设置卡片的区域:</label><br>
                        <div class = "city-cascading" style = "display: inline-block;" id = "cascad-edit"></div>
                        <br />
                        <!--<label class="control-label">摇奖次数(次/人)：</label>-->
                        <!--<input class="form-control" ng-model="updateDate.limitCount" >-->
                        <!--<br />-->
                        <!--<label class="control-label">活动描述：</label><br />-->
                        <!--<textarea style="width:600px;height:200px;" ng-model="updateDate.activityDesc" ></textarea>-->
                        <!--<br /><br />-->
                        <label> 卡片图片</label><br>
                        <div class="col-xs-5">
                            <input type="file" id="pict_edit"
                                   onchange="angular.element(this).scope().selectFile(this.files)" accept="image/*"></div>
                        <br/>
                        <label class="control-label">URL：</label><br />
                        <input type="text" class = "modal-input" style = "width: 600px;display: inline-block;" ng-model="updateDate.url">
                        <br/>
                        <label class="control-label">卡片顺序：</label><br />
                        <input type="text" class = "modal-input" style = "width: 60px;display: inline-block;" ng-model="updateDate  .cardOrder">
                    </form>
                </div>
                <div class = "button-area border-top">
                    <button type="button" class="am-btn am-btn-success right-margin top-margin" ng-show="true" ng-click="update(updateDate,$event)" data-target = "cascad-edit">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!--推送消息-->
    <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-push">
        <div class="am-modal-dialog">
            <div class="am-modal-hd border-bottom" style = "text-align: left;">卡片推送
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>
            <br>
            <div class="am-modal-bd body-area text-left">
                <form>
                    <label>消息内容：</label>
                    <textarea style="width:580px;height:150px;" ng-model="pushMsg" ></textarea>
                </form>
            </div>
            <div class = "button-area border-top">
                <button type="button" class="am-btn am-btn-success right-margin top-margin" ng-show="true" ng-click="cardPushMsg(pushMsg)" data-target = "cascad-search-add">确认</button>
            </div>

        </div>
    </div>

    <!--loading-->
    <div class="am-modal am-modal-loading am-modal-no-btn" id="loading">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">正在推送...</div>
            <div class="am-modal-bd">
                <span class="am-icon-spinner am-icon-spin"></span>
            </div>
        </div>
    </div>

</div>

<script>

    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, //month
            "d+": this.getDate(), //day
            "h+": this.getHours(), //hour
            "m+": this.getMinutes(), //minute
            "s+": this.getSeconds(), //second
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
            "S": this.getMilliseconds() //millisecond
        }
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
                (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o) if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1,
                    RegExp.$1.length == 1 ? o[k] :
                            ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    }




    var fromDate_edit = $('#begin_edit').datetimepicker().on('changeDate', function (ev) {
        $('#begin_edit').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });

    var toDate_edit = $('#end_edit').datetimepicker().on('changeDate', function (ev) {
        $('#end_edit').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });


    var fromDate_add = $('#begin_add').datetimepicker().on('changeDate', function (ev) {
        $('#begin_add').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });

    var toDate_add = $('#end_add').datetimepicker().on('changeDate', function (ev) {
        $('#end_add').datetimepicker({
            format: 'yyyy-mm-dd hh:ii'
        });
    });



</script>